﻿using System;

namespace NDBGen.Plugins.Reflexive
{
    [DatabaseScriptGenerator("Reflexive")]
    public class ReflexiveDatabaseScriptGenerator : IDatabaseScriptFileGenerator
    {
        void IDatabaseScriptFileGenerator.WriteDefineData(String prefix, Table table, ScriptedTableData data, IIndentedTextWriter writer)
        {
            writer.WriteLine("#{0}.{1}", data.TableSchemaName, data.TableName);

            foreach (var column in data.Columns)
            {
                writer.Write("| ");
                writer.Write(column);
                writer.Write('\t');
            }
            writer.WriteLine();
            writer.WriteLine(new String('-', 100));

            var isFirstEntry = true;
            foreach (var entry in data.Entries)
            {
                if (isFirstEntry) isFirstEntry = false;
                else writer.WriteLine();

                var isFirstColumn = true;
                foreach (var value in entry.Values)
                {
                    if (isFirstColumn) isFirstColumn = false;
                    else
                    {
                        writer.Write('\t');
                        writer.Write("| ");
                    }
                    writer.Write(value);
                }
            }
        }

        void IDatabaseScriptFileGenerator.WriteCreateSchema(String schemaName, IIndentedTextWriter writer) { }

        void IDatabaseScriptFileGenerator.WriteCreateTable(Table table, IIndentedTextWriter writer) { }

        void IDatabaseScriptFileGenerator.WriteDefineProcedure(String prefix, Table table, ScriptedTableData data, IIndentedTextWriter writer){ }

        void IDatabaseScriptFileGenerator.WriteDropTable(Table table, IIndentedTextWriter writer) { }

        void IDatabaseScriptFileGenerator.Init(ParsedInput parsedInput)
        {
        }
    }
}
